package com.community.itelligentcommunity.community.myCommunity.service;

import com.community.itelligentcommunity.common.base.dao.GenericDao;
import com.community.itelligentcommunity.common.base.service.GenericService;
import com.community.itelligentcommunity.common.util.user.UserInfo;
import com.community.itelligentcommunity.community.myCommunity.dao.RepairControlDao;
import com.community.itelligentcommunity.community.myCommunity.entity.QueryRepairControlInf;
import com.community.itelligentcommunity.community.myCommunity.entity.RepairControlInf;
import com.community.itelligentcommunity.sys.entity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.text.SimpleDateFormat;
import java.util.Date;

@Service
@Transactional(rollbackFor={IllegalArgumentException.class})
public class RepairControlService extends GenericService<RepairControlInf, QueryRepairControlInf> {

    @Autowired
    private RepairControlDao repairControlDao;

    @Override
    protected GenericDao<RepairControlInf, QueryRepairControlInf> getDao() {
        return repairControlDao;
    }

    @Override
    public boolean save(RepairControlInf entity) throws Exception {
        String str="";
        Date dt = new Date();
        //最后的aa表示“上午”或“下午”    HH表示24小时制    如果换成hh表示12小时制
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        str=sdf.format(dt);
        if(entity.getFixName()== null){
            entity.setFixState("待派人");
        }
        User user = UserInfo.getUser();
        entity.setRepairId(user.getId());
        entity.setRepairDate(str);
        return super.save(entity);
    }

    @Override
    public boolean update(RepairControlInf entity) throws Exception {
        String str="";
        Date dt = new Date();
        //最后的aa表示“上午”或“下午”    HH表示24小时制    如果换成hh表示12小时制
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        str=sdf.format(dt);
        if(entity.getFixName()!= null){
            entity.setFixDate(str);
        }
        return super.update(entity);
    }
}
